package com.app.shell.controller
{
	import com.app.common.GlobalConstants;
	import com.app.shell.message.ShellMessage;
	import com.app.shell.model.ActiveWidgetProxy;
	
	import mx.modules.IModule;
	import mx.modules.IModuleInfo;
	import mx.modules.ModuleManager;

	public class ShellCommand {
		
		[MessageDispatcher] public var dispatcher:Function;
		
		[Inject]
		[Bindable] public var proxy:ActiveWidgetProxy;

		//[MessageHandler(selector=GlobalConstants.CREATE_LOGGER)]
		[MessageHandler(selector='createLogger')]
		public function handleCreateLogger (message:ShellMessage) : void {
			handleWidgetCreation(message.note as String);
			//proxy.createWidget(message.note as String);			
		}

		[MessageHandler(selector='createWidget')]
		public function handleCreateWidget (message:ShellMessage) : void {
			handleWidgetCreation(message.note as String);
		}
		
		[MessageHandler(selector='registerModuleRouterAddress')]
		public function handleRegisterModuleRouterAddress (message:ShellMessage) : void {
			//message.note.router = applicationRouter;
			//message.note.defaultRouteAddress = applicationAddress;
		}

		private function handleWidgetCreation(id:String) : void {
			var widget:IModule = proxy.getWidget(id);
			if (widget)
			{
				dispatcher(new ShellMessage(GlobalConstants.WIDGET_CREATED, id));
			}
			else
			{
				proxy.createWidget(id);
			}
		}
	}
}